package com.twotiger.and.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import app.twotiger.p2p.R;

import com.twotiger.and.bean.Dayinverst;
import com.twotiger.and.util.DateUtil;
import com.twotiger.and.util.ListUtils;

public class DayInverstAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater infiter;
    private List<Dayinverst> list;

    public DayInverstAdapter(Context context, List<Dayinverst> list) {
        super();
        this.context = context;
        this.list = list;
        infiter = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    public void adddata(List<Dayinverst> _List) {
        if (!ListUtils.isEmpty(_List)) {
            list.addAll(_List);
        }
        notifyDataSetChanged();
    }

    public void resetData(List<Dayinverst> _List) {
        list.clear();
        if (!ListUtils.isEmpty(_List)) {
            list.addAll(_List);
        }
        notifyDataSetChanged();
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = infiter.inflate(R.layout.dayinverst_list_item, null);
            holder.item_time = (TextView) convertView.findViewById(R.id.item_time);
            holder.item_money = (TextView) convertView.findViewById(R.id.item_money);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.item_time.setText(DateUtil.getlongtoDate(list.get(position).getDate()));
        holder.item_money.setText(String.valueOf(list.get(position).getInterest()) + "元");
        return convertView;
    }

    class ViewHolder {
        TextView item_money;
        TextView item_time;
    }

}
